import {baseUrl} from './config.js'


// uni.addInterceptor('request', {
//   invoke(args) {
//     // request 触发前拼接 url 
//     args.url = 'https://www.example.com/'+args.url
//   },
//   success(args) {
//     // 请求成功后，修改code值为1
//     args.data.code = 1
//   }, 
//   fail(err) {
//     console.log('interceptor-fail',err)
//   }, 
//   complete(res) {
//     console.log('interceptor-complete',res)
//   }
// })


/**
 * 首页
 * @param {*} id 
 */

// 封装的首页榜单的网络请求
export function getTopList(){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/toplist/detail`,
			methods:'GET',
			data:{
				
			},
			success: res => {
				const {list} = res.data
				reslove(list.splice(0, 4))
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}



// 获取跳转后列表页后的列表
export function getPlayerListInfo(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/playlist/detail?id=${id}`,
			methods:'GET',
			data:{
				
			},
			success: res => {
				let result = res.data.playlist
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}



/**
 * 列表详情页
 * @param {*} id 
 */

// 跳转到列表页后列表详细数据的数据
export function getPlayerList(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/playlist/detail?id=${id}`,
			methods:'GET',
			success: res => {
				let result = res.data.playlist.tracks
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
	
			}
		})
	})
}

// 获取列表页点击详情的数据
export function getListInfo(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/playlist/detail?id=${id}`,
			methods:'GET',
			success: res => {
				let result = res.data.playlist
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}




/**
 * 播放页
 * @param {*} id 
 */
// 获取歌曲详情
export function plyerInfo(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/song/detail?ids=${id} `,
			methods:'GET',
			success: res => {
				let result = res.data.songs
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}

// 获取相似歌曲列表
export function simiPlayer(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/simi/song?id=${id} `,
			methods:'GET',
			data:{
				
			},
			success: res => {
				let result = res.data.songs
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}


export function comment(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/comment/music?id=${id} `,
			methods:'GET',
			data:{
				
			},
			success: res => {
				let result = res.data.hotComments
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}

export function getLyric(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/lyric?id=${id} `,
			methods:'GET',
			success: res => {
				let result = res.data.lrc.lyric
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}

export function song(id){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/song/url?id=${id} `,
			methods:'GET',
			success: res => {
				let result = res.data.data[0]
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}

/*

search页

*/


export function searchHot(){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/search/hot/detail`,
			methods:'GET',
			success: res => {
				let result = res.data.data
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}
export function search(value){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/cloudsearch?keywords=${value}`,
			methods:'GET',
			success: res => {
				let result = res.data.result.songs
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}
export function searchSuggest(value){
	 return new Promise(function(reslove, reject){
		uni.request({
			url: `${baseUrl}/search/suggest?keywords=${value}&type=mobile`,
			methods:'GET',
			success: res => {
				let result = res.data.result.allMatch
				reslove(result)
			},
			fail: () =>{
				
			},
			compele: () => {
				
			}
		})
	})
}
